package com.k4rthik.clipall.network;

import com.k4rthik.clipall.commons.Logger;
import com.k4rthik.clipall.commons.PropertyHandler;

import java.io.IOException;
import java.net.Socket;

/**
 * Created by IntelliJ IDEA.
 * User: k4rthik
 * Date: 3/23/12
 * Time: 11:36 PM
 */

public class ShareClient
{
    String serverName;
    int serverPort;

    Socket serverSocket = null;

    public ShareClient(String _serverName)
    {
        serverName = (_serverName == null) ? PropertyHandler.get("DEFAULT_SERVER_IP") : _serverName;
        serverPort = new Integer(PropertyHandler.get("DEFAULT_SERVER_PORT"));
    }

    public ShareClient(String _serverName, int _portNumber)
    {
        serverName = (_serverName == null) ? PropertyHandler.get("DEFAULT_SERVER_IP") : _serverName;
        serverPort = _portNumber;
    }

    public void connectToServer()
    {
        try
        {
            Logger.log("Connecting to server @ "+serverName+":"+serverPort);
            serverSocket = new Socket(serverName, serverPort);
            Logger.log("Connected to server " + serverSocket.getRemoteSocketAddress());
            Connections.addServerConnection(serverSocket);
        } catch(IOException e) {
            Logger.log("Could not connect to server.", e);
        }
    }
}
